package com.groupbuying.orderproducer.mq;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 订单交易状态及支付安状态变更生产者
 * @Author Vincentxin
 * @Date 2019-05-10
 */
@Configuration
public class OrderMQProducer {

    public static final Logger LOGGER = LoggerFactory.getLogger(OrderMQProducer.class);

    public OrderMQProducer() {
    }

    @Bean
    public Producer getOrderMQProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, OrderMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, OrderMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, OrderMQConfig.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            LOGGER.info("producer is start !!!  groupId:{" + OrderMQConfig.GROUP_ID + "}");
        } catch (Exception var4) {
            LOGGER.error(String.format("producer is error  groupId:{" + OrderMQConfig.GROUP_ID + "}", var4.getMessage(), var4));
        }

        return producer;
    }
}
